package com.attilax.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;

import com.attilax.json.AtiJson;
import com.attilax.util.SpringUtil;
import com.github.abel533.sql.SqlMapper;
import com.taYu.dao.UsersMapper;
import com.taYu.model.Users;
import com.taYu.service.UsersService;
import com.taYu.util.MD5;

public class mybatisTest {
	
	public static void main(String[] args) throws Exception {
	
	//	org.slf4j.impl.StaticLoggerBinder.getSingleton();
		Map<String,String> map =new HashMap<String, String>();
		map.put("username", "admin");
		map.put("password", MD5.MD5Encode("admin"));
		
		
	//    li3();
	//	UsersMapper userdao=  	 SpringUtil.build4wash().getBeanV2(UsersMapper.class);
	//  	li(map);
		
		org.mybatis.spring.SqlSessionFactoryBean  factoryBean=SpringUtil.build4wash().getBeanV2(SqlSessionFactoryBean.class);
	 	SqlSessionFactory sql_sessionFactory = factoryBean.getObject();
	 	  SqlSession sqlSession = sql_sessionFactory.openSession();
	 	//创建sqlMapper
	 	 SqlMapper sqlMapper = new SqlMapper(sqlSession);
		//查询，返回List<Map>
		List<Map<String, Object>> list = sqlMapper.selectList("select * from s_member limit 3");
	 System.out.println(AtiJson.toJson(list));
		//t2(map);
	  //     List li=   sqlSession.selectList("getLockTables", 9999999);
	// sqlSessionFactory.
		System.out.println("f");
	}

	private static void li3() {
		UsersService us=  (UsersService) SpringUtil.build4wash().getBeanV2("usersService");
	 	Users  result = us.QueryByUsersByNameAndPassword("admin", "admin");
	 	System.out.println(AtiJson.toJson(result));
	}

	private static void t2(Map<String, String> map) throws Exception {
		org.mybatis.spring.SqlSessionFactoryBean  factoryBean=SpringUtil.build4wash().getBeanV2(SqlSessionFactoryBean.class);
	 	SqlSessionFactory sessionFactory = factoryBean.getObject();
	 	  SqlSession sqlSession = sessionFactory.openSession();
	      List li=   sqlSession.selectList("QueryByUsersByMap", map);
 
			System.out.println( AtiJson.toJson(li));
	}

	private static void li(Map<String, String> map) {
		UsersMapper userdao=  	 (UsersMapper) SpringUtil.build4wash().getBeanV2(UsersMapper.class);
		
		List list=userdao.QueryByUsersByMap(map);
		System.out.println(AtiJson.toJson(list));
	}

}
